package onetotwenty;

import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.*;

import org.junit.Test;

public class Util {
	public static long sqrt(long l) {
		for (long i = 1L; i < l; i++) {
			if (i * i >= l) {
				return i;
			}
		}
	
		return l;
	}
	
	public static boolean isPrimeNumber(long l) {
		if(l <= 1) {
			throw new RuntimeException("잘못된 인자입니다.");
		}

		long end = sqrt(l);
		System.out.println(end);
		for (long i = 2; i <= end; i++) {
			if (l % i == 0 && l != i) {
				return false;
			}
		}
	
		return true;
	}
	
	@Test
	public void isPrime() {
		assertThat(isPrimeNumber(2), is(true));
	}
}

